package com.stox.core.manager;

import java.io.File;

import com.stox.core.util.PropertiesUtil;
import com.stox.design.ApplicationConfigurer;
import com.stox.ioc.Container;

public class InstallationManager implements ApplicationConfigurer<Void, Void> {

	private PropertiesUtil propertiesUtil;
	
	public InstallationManager() {
		this.propertiesUtil = Container.get(PropertiesUtil.class);
	}
	
	@Override
	public int getOrder() {
		return 1;
	}
	
	@Override
	public Void invoke(Void payload) {
		createPath(getConfigurationPath());
		createPath(getLibraryPath());
		createPath(getBinPath());
		createPath(getDatabasePath());
		createPath(getFilebasePath());
		return null;
	}
	
	private void createPath(String path){
		File file = new File(path);
		if(!file.exists()){
			file.mkdirs();
		}
	}

	public String getConfigurationPath(){
		return propertiesUtil.get("path.installation")+File.separator+propertiesUtil.get("path.configuration");
	}
	
	public String getLibraryPath(){
		return propertiesUtil.get("path.installation")+File.separator+propertiesUtil.get("path.lib");
	}
	
	public String getBinPath(){
		return propertiesUtil.get("path.installation")+File.separator+propertiesUtil.get("path.bin");
	}
	
	public String getDatabasePath(){
		return propertiesUtil.get("path.installation")+File.separator+propertiesUtil.get("path.database");
	}
	
	public String getFilebasePath(){
		return propertiesUtil.get("path.installation")+File.separator+propertiesUtil.get("path.filebase");
	}
}
